package com.beiing.tianshuai.tianshuai.mine.presenter;

import com.beiing.tianshuai.tianshuai.base.BasePresenter;
import com.beiing.tianshuai.tianshuai.entity.FollowBean;
import com.beiing.tianshuai.tianshuai.entity.FollowResultBean;
import com.beiing.tianshuai.tianshuai.entity.PersonalInfoBean;
import com.beiing.tianshuai.tianshuai.mine.model.MineModel;
import com.beiing.tianshuai.tianshuai.mine.model.MineModelImpl;
import com.beiing.tianshuai.tianshuai.mine.view.MineViewImpl;
import com.beiing.tianshuai.tianshuai.util.LogUtils;

/**
 * Created by Jinni on 2017/7/26 0026.
 */

public class MinePresenter extends BasePresenter implements MinePresenterImpl, MineModel.OnRequestListener{

    private MineViewImpl mMineView;
    private MineModelImpl mMineModel;

    public MinePresenter(MineViewImpl mineView) {
        mMineView = mineView;
        mMineModel = new MineModel(this);
    }

    @Override
    public void getPersonalInfoResult(String uid) {
        mMineView.showProgress();
        mMineModel.getPersonalInfoResult(uid);
    }

    @Override
    public void isFollowed(String fromUid, String toUid) {
        mMineModel.isFollowed(fromUid, toUid);
    }

    @Override
    public void isFollowed(FollowBean bean) {
        LogUtils.i(String.valueOf(bean.getCode()),"minePresenter");
        mMineView.isFollowed(bean.getCode() == 1);
    }

    @Override
    public void followResult(FollowResultBean bean) {
        mMineView.getFollowResult(bean);
    }

    @Override
    public void onSuccess(PersonalInfoBean bean) {
        mMineView.hideProgress();
        mMineView.onRequestSuccess(bean);
    }

    @Override
    public void onError(Throwable e) {
        mMineView.hideProgress();
        mMineView.onRequestFailed(e);
    }

    public void setFollowed(String fromUid, String toUid) {
        mMineModel.setFollowed(fromUid, toUid);
    }
}
